package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.OP13;
import ar.edu.caece.compiler.grammar.terminals.RestaEnteroToken;

public class OP13Factory extends AbstractTokenVisitorFactory {

	private static OP13Factory INSTANCE;
	
	public static OP13Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new OP13Factory();
		return INSTANCE;
	}
	
	private OP13Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new RestaEnteroToken.RestaEnteroChainVisitor(siguiente) {
			
			@Override
			public Recognizer restaEnteroCase(RestaEnteroToken llamador) {
				OP13 op13 = new OP13(llamador);
				op13.addAttribute("tipo", new StringAttribute("ENTERO"));
				op13.addAttribute(Attribute.OPERACION, new StringAttribute("RESTA"));

				return op13;			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new RestaEnteroToken.RestaEnteroTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"OP13",new ParsingException("Error de parsing.",OP13.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer restaEnteroCase(RestaEnteroToken llamador) {
				OP13 op13 = new OP13(llamador);
				op13.addAttribute("tipo", new StringAttribute("ENTERO"));
				op13.addAttribute(Attribute.OPERACION, new StringAttribute("RESTA"));

				return op13;
			}
		};
	}
	
	
}
